<%@ tag body-content="empty" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="spring-sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="cf" uri="http://kyub.com/jsp/jstl/functions" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net/el" %>
<%@ attribute name="pojoDescriptor" required="true" type="com.kyub.spring.gears.model.PojoDescriptor" %>
<%@ attribute name="pojo" required="true" type="java.lang.Object" %>
<%@ attribute name="gears_restfull_prefix" required="true" %>


<h2>${pojoDescriptor.name}</h2>

<display:table name="pojoList" uid="pojo">
    <c:forEach items="${pojoDescriptor.listFields}" var="p">
        <c:if test="${!cf:isStructProperty(p) or (cf:isStructProperty(p) and p.layout.label == null)}">
            <spring:message var="colTitle" code="${pojoDescriptor.name}.${p.name}.labelList" text="${p.name}"
                            htmlEscape="true"/>
        </c:if>
        <display:column sortable="true" title="${colTitle}">
            <c:choose>
                <c:when test="${cf:isSimpleProperty(p)}">
                    <c:choose>
                        <c:when test="${cf:readProperty(pojo,p.name).class.simpleName == 'Date'}">
                            <fmt:formatDate value="${cf:readProperty(pojo,p.name)}"/>
                        </c:when>
                        <c:when test="${cf:readProperty(pojo,p.name).class.simpleName == 'Boolean'}">
                            <img src="${pageContext.request.contextPath}/css/images/${cf:readProperty(pojo,p.name)}.png"
                                 alt="${cf:readProperty(pojo,p.name)}"/>
                        </c:when>
                        <c:otherwise>
                            ${cf:readProperty(pojo,p.name)}
                        </c:otherwise>
                    </c:choose>

                </c:when>
                <c:when test="${cf:isRelation(p)}">
                    <c:if test="${not empty p.pojoDescr}">
                        <a href="${pageContext.request.contextPath}/${gears_restfull_prefix}/${p.pojoDescr.name}/view/${cf:readProperty(cf:readProperty(pojo,p.name),p.pojoDescr.idProperty)}?backPojo=${pojoDescriptor.name}&height=300&width=300"
                           class="thickbox"> ${cf:readProperty(pojo,p.name)}</a>
                    </c:if>
                    <c:if test="${empty p.pojoDescr}">
                        ${cf:readProperty(pojo,p.name)}
                    </c:if>
                </c:when>
                <c:when test="${cf:isCollection(p)}">
                    <a href="${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/viewrelated/${cf:readProperty(pojo,pojoDescriptor.idProperty)}/${p.name}?backPojo=${pojoDescriptor.name}&height=300&width=450"
                       class="thickbox">${p.name} </a>
                </c:when>
                <c:when test="${cf:isStructProperty(p)}">
                    <!--
                    ${p.layout.hrefPattern != null}  ${p.layout.label != null}
                    -->
                    <c:choose>
                        <c:when test="${p.layout.hrefPattern != null}">

                            <a href="${cf:buildHref(p.layout, pojo,pageContext.request.contextPath)}">
                                <c:choose>
                                    <c:when test="${p.layout.label != null}">
                                        <spring:message code="${pojoDescriptor.name}.${p.layout.label}"
                                                        text="${p.layout.label}" htmlEscape="false"/>
                                    </c:when>
                                    <c:otherwise>
                                        ${cf:readProperty(pojo,p.property.name)}
                                    </c:otherwise>
                                </c:choose>
                            </a>
                        </c:when>

                        <c:otherwise>
                            <c:when test="${p.layout.label != null}">
                                <spring:message code="${pojoDescriptor.name}.${p.layout.label}"
                                                text="${p.layout.label}"
                                                htmlEscape="false"/>
                            </c:when>
                            <c:otherwise>
                                ${cf:readProperty(pojo,p.property.name)}
                            </c:otherwise>
                        </c:otherwise>

                    </c:choose>


                </c:when>
                <c:otherwise>
                    ${p} ${p.class}
                </c:otherwise>
            </c:choose>

        </display:column>
    </c:forEach>

    <display:column>
        <a href="${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/view/${cf:readProperty(pojo,pojoDescriptor.idProperty)}">view</a>
    </display:column>
    <c:if test="${pojoDescriptor.editable}">
        <display:column>
            <a href="${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/update/${cf:readProperty(pojo,pojoDescriptor.idProperty)}">edit</a>
        </display:column>
    </c:if>


</display:table>